namespace LogikBug.Utilities
{
	/// <summary>
	/// 
	/// </summary>
	public static class MathFunctions
	{
		/// <summary>
		/// 
		/// </summary>
		/// <param name="width"></param>
		/// <param name="height"></param>
		/// <param name="maxWidth"></param>
		/// <param name="maxHeight"></param>
		/// <returns></returns>
		public static int[] ConstrainProportions(int width, int height, int maxWidth, int maxHeight)
		{
			double widthRatio = width / (double)maxWidth;
			double heightRatio = height / (double)maxHeight;
			double resizeRatio = (widthRatio > heightRatio) ? widthRatio : heightRatio;
			
			return new[] { (int)(width / resizeRatio), (int)(height / resizeRatio) };
		}

		/// <summary>
		/// 
		/// </summary>
		/// <param name="width"></param>
		/// <param name="height"></param>
		/// <param name="maxWidth"></param>
		/// <param name="maxHeight"></param>
		/// <returns></returns>
		public static int[] ConstrainProportionsIfLarger(int width, int height, int maxWidth, int maxHeight)
		{
			if(width <= maxWidth && height <= maxHeight)
			{
				return new[] { width, height };
			}

			return ConstrainProportions(width, height, maxWidth, maxHeight);
		}
	}
}